window.workspace = function(){
	var response  = <?#$respons?>;
	var store, sm, grid, form, win, sid={'name':Ext.id()};
	function addForm(node) {
		if(!win) {
		    form = new Ext.form.FormPanel({
				frame		: true,
				border		: false,
				bodyStyle	: 'padding:8px;',
		        labelWidth	: 80,
		        labelAlign  : 'right',
		    	defaults	: {
		    		xtype	  : 'textfield'
		    	},
		    	items		: [{
		            xtype		: 'hidden',
		            name		: 'id',
		            value 		: 0
		    	},{
		            xtype		: 'textfield',
		            fieldLabel	: '节点表单名字',
		            width		: 220,
		            name		: 'name',
		            allowBlank	: false
		    	},{
		            xtype		: 'textarea',
		            fieldLabel	: '表单内容',
		            name		: 'panelobj',
		            width		: 700,
		            height		: 420,
		            allowBlank	: false
		    	},{
		            xtype		: 'textarea',
		            fieldLabel	: '表单按钮',
		            name		: 'panelbtn',
		            width		: 700,
		            height		: 120,
		            allowBlank	: false
		    	}]
			});
			win = new Ext.Window({
				title	: '新增节点表单',
				iconCls	: 'icon-add',
				width	: 860,
				height	: 680,		
				items	: [form],
				closeAction : 'hide',
				bbar 	: {
					xtype		: 'toolbar',
					buttonAlign	: 'right',
					items		: [{
						text	: '保存', 
						iconCls	: 'icon-save',
						url     : '/admin/workflow/view/dosave.html',
						handler:function(){
						if(!form.getForm().isValid())
		        			return;
		        		form.getForm().submit({
			        		waitMsg 	: '数据提交处理中...',
							waitTitle 	: '信息提示',
			        		clientValidation: true,
			        		url		: '/admin/workflow/view/dosave.html',
				        	success	: function(form, action) {
				        		grid.store.reload();
				        		win.hide();
							},
							failure	: main.submitFailure
				    	});
					}}]
				}
			});
		}
		var id = Ext.isObject(node)? node.get('id'):0;
		win.setTitle((id > 0)? '编辑节点表单':'新增节点表单');
		win.setIconClass((id > 0)? 'icon-edit':'icon-add');
		win.show();
		if(id < 1) {
			form.getForm().reset();
		} else {
	    	form.getForm().loadRecord(node);
		}
	}
	store = new Ext.data.JsonStore({
	    autoDestroy	: true,
	    url			: '/admin/workflow/view/dolist.html',
	    remoteSort	: true,
	    sortInfo	: {
            field		: 'id',
            direction	: 'DESC'
		},
		baseParams	: {
			start	: 0,
			limit	: main.pageSize
		},
		autoLoad		: true,
	    root			: 'dataset',
	 	totalProperty	: 'total',
	    fields			: ['id', 'name', 'panelobj', 'panelbtn']
	});
	sm   = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
 	grid = {
		xtype		: 'grid',
		title		: response.title,
	    store		: store,
		region		: 'center', 
	    columns		: [
	    	sm,
			{header: 'ID编号',width:80,sortable:true,dataIndex:'id'},
			{header: '名称', width:140, dataIndex:'name'},
			{header: '表单信息', width:480, dataIndex:'panelobj'},
			{header: '表单按钮', width:480, dataIndex:'panelbtn'}
		],
	    viewConfig	: {
	        forceFit	 : true,
	        scrollOffset : 0
	    },
	    sm			: sm,
	    listeners 	:{'rowdblclick':function(grid, index, e){
	    	var node = grid.store.getAt(index).copy();
	    	addForm(node);
	    },'destroy':function(){
	    	win && win.close();
	    }},
	    stripeRows	: true,
	    tbar		: [{
			text	: '刷新',
			iconCls	: 'icon-refresh',
			handler : function(){
					store.reload(); 
				}
			},'-',{
			text	: '新增表单',
			iconCls	: 'icon-add',
			url     : '/admin/workflow/view/dosave.html',
			handler : function(){
					addForm(0);
				}
			},'-',{
			text	: '备份数据',
			iconCls	: 'icon-edit',
			url     : '/admin/workflow/view/dobackup.html',
			handler : function(){
					Ext.Ajax.request({
						url		: '/admin/workflow/view/dobackup.html',
						success : function(resp, req){
							var data = Ext.decode(resp.responseText);
							var msg  = (data.code == 0)? '数据备份完成!':data.msg;
							Ext.Msg.alert('信息提示', msg);
						}
					});
				}
			},'-',{
			text	: '删除表单',
			iconCls	: 'icon-delete',
			url     : '/admin/workflow/view/dodelete.html',
			handler : function(){
					var rs = sm.getSelected();
					if(!rs) {
						Ext.Msg.alert('信息提示','请先选择要删除的节点表单！');return;
					}
					Ext.Msg.confirm('信息提示', '您确认要删除该表单？删除将不能恢复。',
						function(btn){
							if(btn != 'yes') {
								return;
							}
					        Ext.Ajax.request({
								url		: '/admin/workflow/view/dodelete.html',
								params 	: {'id':rs.get('id')},
								success : function(resp, req){
									var data = Ext.decode(resp.responseText);
									if(data.code != 0) {
										Ext.Msg.alert('信息提示', data.msg);
									}
									store.reload(); 
								}
							});
					});
				}
			},'-','<b>检索资料：</b>','表单名称:',{
				xtype       : 'textfield',
				id	    	: sid.name,
				width	    : 80
			},'-',{
			text			: '检索',
			iconCls			: 'icon-search',
			handler: function() {
				store.baseParams.name  = Ext.getCmp(sid.name).getValue();
				store.reload(); 
			}
		}],
		bbar		: new Ext.PagingToolbar({
			pageSize	: main.pageSize,
			store		: store,
			displayInfo	: true
		})
	};
	return grid;
}();